package yhao.demo.web.firstWeb.remote;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yhao.demo.service.person.apilist.form.PersonEditForm;
import yhao.demo.service.person.apilist.form.PersonInsertForm;
import yhao.demo.service.person.apilist.form.PersonQueryForm;
import yhao.demo.service.person.apilist.model.PersonModel;
import yhao.demo.service.person.apilist.restful.PersonFeign;
import yhao.demo.service.person.dubboapi.PersonDubbo;
import yhao.infra.apilist.validate.IdForm;
import yhao.infra.common.model.Pagination;

import javax.annotation.Resource;

/**
 * 人员记录门面层remote
 * Created by yoara on 2019-03-28
 * //自行决定降级
 */
@Service
public class PersonManagerRemote {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private PersonFeign personFeign;
    @Resource
    private PersonDubbo personDubbo;

    @HystrixCommand
    public PersonModel selectById(IdForm form) {
        return personFeign.selectById(form).pickBody();
    }

    @HystrixCommand
    public PersonInsertForm insertPerson(PersonInsertForm form) {
        return personFeign.insertPerson(form).pickBody();
    }

    @HystrixCommand
    public PersonEditForm editPerson(PersonEditForm form) {
        return personFeign.editPerson(form).pickBody();
    }

    @HystrixCommand
    public Pagination<PersonModel> queryPersonPage(PersonQueryForm form) {
        return personFeign.queryPersonPage(form).pickBody();
    }

    @HystrixCommand
    public IdForm deleteById(IdForm form) {
        return personFeign.deleteById(form).pickBody();
    }

    /**使用dubbo查询**/
    public String showNameById(IdForm form) {
        return personDubbo.showNameById(form.getId());
    }
}
